/**select之间的值传递，select在同一页面时通用*/
function cutTo(sourceId, targetId, multiple){
	var source = document.getElementById(sourceId);
	var target = document.getElementById(targetId);
	var ops = source.options;
	var targetOps = target.options;
	
	var opsSelected = returnSelectedNumber(ops);
	var targetOpsSelected = returnSelectedNumber(targetOps);
	
	var le = targetOps.length;
	if(multiple=='false' && le > 0){
		alert('只能单选，必须先删除当前已选选项'); 
		return false;
	}
	
	
    if(multiple=='true'||(isNaN(parseInt(multiple))==false&&(opsSelected+targetOps.length)<=parseInt(multiple))){
		for(var i = 0; i < ops.length; i++){
			var op = ops[i];
			if(op.selected){
				source.removeChild(op);
				var add = true;			
				for(var j = 0; j < targetOps.length; j++){
					if(targetOps[j].value == op.value){
						add = false;
						break;
					}
				}
				if(add)
					target.appendChild(op);
				op.selected = false;
				i--;
			}
		}
    }else{
    	if(isNaN(parseInt(multiple))==false){
			alert('选择项数目不能超过'+parseInt(multiple)+'个')
		}
    }
}


/**select之间的值传递，select在同一页面时通用*/
function cutAllTo(sourceId, targetId,multiple){
	var source = document.getElementById(sourceId);
	var target = document.getElementById(targetId);
	var ops = source.options;
	var targetOps = target.options;
	
	if(multiple=='true'||(isNaN(parseInt(multiple))==false&&(ops.length+targetOps.length)<=parseInt(multiple))){
		for(var i = 0; i < ops.length; i++){
			var op = ops[i];
			source.removeChild(op);
			var add = true;			
			for(var j = 0; j < targetOps.length; j++){
				if(targetOps[j].value == op.value){
					add = false;
					break;
				}
			}
			if(add)
				target.appendChild(op);
			op.selected = false;
			i--;
		}
	}else{ 
		if(multiple!='false'&&isNaN(parseInt(multiple))==false){
			alert('选择项数目不能超过'+parseInt(multiple)+'个')
		}
	}
}

//返回多选框选中的个数
function returnSelectedNumber(theOptions){
	var number = 0;
	if(theOptions){
		for(var i=0;i<theOptions.length;i++){
			if(theOptions[i].selected){
				number++;
			}
		}
	}
	return number;
}


function returnImportValue(id, name){
	var arr = new Array();
	arr[0] = id;
	arr[1] = name;
	window.returnValue = arr;
	window.close();
}
		
function returnImportValues(id){
	var source = document.getElementById(id);
	var ops = source.options;
	var ids = new Array();
	var names = new Array();
	var arr = new Array();
	for(var i = 0; i < ops.length; i++){
		ids[i] = ops[i].value;
		names[i] = ops[i].innerText;
	}
	arr.push(ids);
	arr.push(names);
	window.returnValue = arr;
	window.close();
}

/**进行长时间的加载时，为页面添加屏蔽层*/
function lock(){
	new ProcessBar().show();
}

function unlock(){
	new ProcessBar().hide();
}

function showDialog(url, width, height, params){
	var param = null;
	if(!isNaN(width) || width.indexOf('px') < 0)
		width = width + 'px';
	if(!isNaN(height) || height.indexOf('px') < 0)
		height = height + 'px';

	if(params)
		param = params;
	else if(url.indexOf('?') > 0){
		var paramString = url.substr(url.indexOf('?') + 1);
		param = new Array();
		var paramArray = paramString.split('&');
		var paramMap = new Object();
		for(var i = 0; i < paramArray.length; i++){
			var map = paramArray[i].split('=');			
			if(map.length > 1)
				eval('paramMap.' + map[0] + '="' + map[1] + '"');			
		}
		param.push(paramMap);
	}
	window.showModalDialog(url, param, 'dialogWidth:' + width + ',dialogHeight:' + height);
}